﻿using System;
using System.Web;
using BusinessObject;
using Model;

namespace ViewLayer.Pages.Historys
{
    public partial class CadastroHistory : System.Web.UI.Page
    {
        User user;
        private static string vision = "History";

        protected void Page_Load(object sender, EventArgs e)
        {
            user = (User)Session["User"];
            if (user == null)
            {
                Response.Redirect("../Account/Login.aspx");
            }
        }

        protected void btnSaveExit_Click(object sender, EventArgs e)
        {
            History history = createHistory();

            if (history != null)
            {
                HistoryBO.Instance.Save(history);
                HttpContext.Current.Session.Add("History", history);
                Response.Redirect("../Tasks/InicioTask.aspx");
            }
            else
            {
            }
        }

        private History createHistory()
        {
            History history = new History();
            history.Nome = txtNome.Text;
            history.Descricao = txtDescricao.Text;
            history.MelhorCaso = double.Parse(txtMelhorCaso.Text);
            history.CasoMedio = double.Parse(txtMaisProvavel.Text);
            history.PiorCaso = double.Parse(txtPiorCaso.Text);
            history.Project = (Project)Session["Project"];

            if (getEpicSession() != null)
            {
                history.Epic = getEpicSession();
            }

            return history;
        }

        private Epic getEpicSession()
        {
            return (Epic)Session["Epic"];
        }

        protected void btnSaveContinue_Click(object sender, EventArgs e)
        {
            History history = createHistory();

            if (history != null)
            {
                HistoryBO.Instance.Save(history);
                Response.Redirect("../Historys/CadastroHistory.aspx");
            }
            else
            {
            }
        }

        protected void btnVoltar_Click(object sender, EventArgs e)
        {
            Response.Redirect("../Historys/InicioHistory.aspx");
        }

        protected void lkbCadastrarHistoriaType_Click(object sender, EventArgs e)
        {
            Response.Redirect("../Tipos/CadastroTipo.aspx");
        }
    }
}